<link rel="stylesheet" href="<?php echo $this->shopHelper()->baseCssPath('template/pc/default/css/stylesheet.css'); ?>?v=<?php echo time(); ?>">
<script src="<?php echo $this->shopHelper()->baseCssPath('template/pc/default/js/frontJs.js'); ?>"></script>
<script src="<?php echo $this->shopHelper()->baseJsPath('template/pc/default/js/layer/layer.js'); ?>"></script>
<script src="<?php echo $this->shopHelper()->baseCssPath('template/pc/default/js/headCommon.js'); ?>?v=<?php echo time(); ?>"></script>

<body>
<?php
$form = $this->form;
$form->prepare();
$form->setAttributes(['class' => 'form-horizontal']);

$form->get('trueName')->setAttributes(['class' => 'form-control', 'style' => 'height:30px;', 'placeholder' => $this->translate('收货人姓名')]);
$form->get('phone')->setAttributes(['class' => 'form-control', 'style' => 'height:30px;','placeholder' => $this->translate('收货人电话')]);
$form->get('addressInfo')->setAttributes(['class' => 'form-control', 'style' => 'height:30px;width:40%;','placeholder' => $this->translate('详细地址')]);
$form->get('postCode')->setAttributes(['class' => 'form-control', 'style' => 'height:30px;', 'placeholder' => $this->translate('邮政编码')]);
?>
<div>
    <div class="xm-plain-box">
        <div class="box-bd">
            <div class="row">
                <?php echo $this->form()->openTag($form); ?>
                <?php echo $this->formElement($form->get('shopCsrf')); ?>
                <?php echo $this->formElementErrors($form->get('shopCsrf'), ['class'=>'error-message']); ?>
                <div class="control-group">
                    <label for="input01" class="control-label"><?php echo $this->translate('收货人姓名'); ?><span class="must_add_value">*</span>：</label>
                    <div class="controls">
                        <?php echo $this->formElement($form->get('trueName')); ?>
                        <?php echo $this->formElementErrors($form->get('trueName'), ['class'=>'error-message']); ?>
                    </div>
                </div>
                <div class="control-group">
                    <label for="input01" class="control-label"><?php echo $this->translate('收货人电话'); ?><span class="must_add_value">*</span>：</label>
                    <div class="controls">
                        <?php if(count($this->phoneArea) == 1) { ?>
                            <?php echo $this->formElement($form->get('areaCode')); ?>
                            <?php echo $this->formElementErrors($form->get('areaCode'), ['class'=>'error-message']); ?>
                            <?php echo $this->formElement($form->get('phone')); ?>
                            <?php echo $this->formElementErrors($form->get('phone'), ['class'=>'error-message']); ?>
                        <?php } else { $form->get('areaCode')->setAttributes(['class' => 'form-control']); ?>
                            <div class="row">
                                <div class="span2">
                                    <?php echo $this->formElement($form->get('areaCode')->setAttributes(['style' => 'width:90%;'])); ?>
                                    <?php echo $this->formElementErrors($form->get('areaCode'), ['class'=>'error-message']); ?>
                                </div>
                                <div class="span8">
                                    <?php echo $this->formElement($form->get('phone')); ?>
                                    <?php echo $this->formElementErrors($form->get('phone'), ['class'=>'error-message']); ?>
                                </div>
                            </div>
                        <?php } ?>
                    </div>
                </div>
                <div class="control-group">
                    <label for="input01" class="control-label"><?php echo $this->translate('地区'); ?><span class="must_add_value">*</span>：</label>
                    <div class="controls" id="region">
                        <?php if(isset($this->addressInfo)) { ?>
                            <span class="show_region_value"><?php echo $this->addressInfo->getRegionValue();?></span>
                            <button type="button" onclick="regionEdit();" class="btn btn-success btn-sm show_region_value"><i class="fa fa-pencil"></i> <?php echo $this->translate('修改')?></button>
                        <?php } ?>
                        <select id="show_address_area" name="show_address_area" class="form-control" style="display: inline;width: 15%;<?php echo isset($this->addressInfo) ? 'display: none' : '';?>">
                            <option value=""><?php echo $this->translate('请选择'); ?></option>
                            <?php if ($this->region and !empty($this->region)) {
                                foreach ($this->region as $value) {
                                    ?>
                                    <option
                                            value="<?php echo $value->getRegionId(); ?>"><?php echo $value->getRegionName(); ?></option>
                                    <?php
                                }
                            }
                            ?>
                        </select>
                        <?php echo $this->formElement($form->get('regionId')); ?>
                        <?php echo $this->formElementErrors($form->get('regionId'), ['class'=>'error-message']); ?>
                        <?php echo $this->formElement($form->get('regionValue')); ?>
                        <?php echo $this->formElementErrors($form->get('regionValue'), ['class'=>'error-message']); ?>
                    </div>
                </div>
                <div class="control-group">
                    <label for="input01" class="control-label"><?php echo $this->translate('详细地址'); ?><span class="must_add_value">*</span>：</label>
                    <div class="controls">
                        <?php echo $this->formElement($form->get('addressInfo')); ?>
                        <?php echo $this->formElementErrors($form->get('addressInfo'), ['class'=>'error-message']); ?>
                    </div>
                </div>
                <div class="control-group">
                    <label for="input01" class="control-label"><?php echo $this->translate('邮政编码'); ?>：</label>
                    <div class="controls">
                        <?php echo $this->formElement($form->get('postCode')); ?>
                        <?php echo $this->formElementErrors($form->get('postCode'), ['class'=>'error-message']); ?>
                    </div>
                </div>
                <div class="control-group">
                    <label for="input01" class="control-label"><?php echo $this->translate('默认地址'); ?>：</label>
                    <div class="controls">
                        <label class="checkbox">
                            <?php echo $this->formElement($form->get('addrDefault')); ?> <?php echo $this->translate('是'); ?>
                        </label>
                        <?php echo $this->formElementErrors($form->get('addrDefault'), ['class'=>'error-message']); ?>
                    </div>
                </div>
                <div class="control-group">
                    <div class="controls">
                        <button id="button-submit" type="submit" class="btn btn-primary"><?php echo $this->translate('提交收货地址信息'); ?></button>
                    </div>
                </div>
                <?php echo $this->form()->closeTag(); ?>
            </div>
        </div>
    </div>
</div>
<script>
    <?php if($this->status) echo "layer.load(2, {shade: [0.05, '#000'] });parent.location.reload();"; ?>

    var SITE_REGION_URL = '<?php echo $this->url('shop-home', ['action' => 'ajaxRegion']);?>';
    var AREA_SELECT_LANG = '<?php echo $this->translate('请选择'); ?>';
    regionInit("region");

    $(document).ready(function() {
        $("#<?php echo $form->getName(); ?>").validate({
            rules: {
                trueName: {
                    required: true
                },
                addressInfo: {
                    required: true
                },
                phone: {
                    required: true
                }
            },
            messages: {
                trueName: {
                    required: "<?php echo $this->translate('请输入收货人姓名!'); ?>"
                },
                addressInfo: {
                    required: "<?php echo $this->translate('详细地址不能为空!'); ?>"
                },
                phone: {
                    required: "<?php echo $this->translate('收货人电话不能为空!'); ?>"
                }
            }
        });
    });
</script>
</body>